<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自定义指令</title>
    <script src="https://unpkg.com/vue@next"></script>
</head>
<body>
    <div id="Application">
        <input v-getfocus:custom="1" />
        <br>
        自定义指令支持 beforeMount、beforeUpdate、updated、beforeUnmount、unmounted
    </div>
    <script>
        const App = Vue.createApp({})
        App.directive("getfocus",{
            
            mounted(ele,param){
                console.log(param)
                if(param.value == "1"){
                    console.log("自定义指令使组件获得焦点")
                    ele.focus()
                }
            }
        })
        /*** 也可在组件定义域中局部注册 ***/
        const comp = {
            directives: {
                getforus:{
                    mounted(el){
                        el.focus();
                    }
                }
            },
            mounted(){
                console.log(this.version)
            }
        }
        App.component("comp",comp)
        App.mount("#Application")
    </script>
</body>
</html>